package org.zizi.db.plan.reader;

import java.sql.ResultSet;

import org.zizi.db.column.ColumnReader;
import org.zizi.db.plan.ResultReader;

public class ArrayResultReader<T> implements ResultReader<T>
{
	private Class<T> type;
	private ColumnReader[] readers;
	
	public ArrayResultReader(Class<T> type, ColumnReader[] readers)
	{
		this.type = type;
		this.readers = readers;
	}

	public T build(ResultSet rs) throws Exception
	{
		Object[] array = new Object[readers.length];
		for (int i = 0; i < readers.length; i++)
		{
			array[i] = readers[i].read(rs, i + 1);
		}
		
		return type.cast(array);
	}
}
